package com.example.jetpacktest.databinding

import android.os.Bundle
import android.os.PersistableBundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.jetpacktest.R
import com.example.jetpacktest.domain.User

class DataBindingTest1Activity: AppCompatActivity() {

    private lateinit var binding: ActivityDataBindingTest1Binding

    private lateinit var user: User

    private var count: Int = 0;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_data_binding_test1)
        user = User("张三", "123456")
        binding.user = user

        //点击按钮，界面并不会更新，要想数据更新之后，界面跟着更新，请使用LiveData(LiveData一般是放在ViewModel中的)
        binding.btn1.setOnClickListener {
            count++;
            user.userName = user.userName + ", " + count
            user.password = user.password + ", " + count
        }
    }

}